



//
//  ZSignViewController.m
//  ZQLearn
//
//  Created by macfeel on 2019/5/10.
//  Copyright © 2019 macfeel. All rights reserved.
//

#import "ZSignViewController.h"
#import "ZSignDetailViewController.h"
#import "YQCalendarView.h"
#import "ImageShowScroll.h"
@interface ZSignViewController ()<YQCalendarViewDelegate>
@property (nonatomic ,strong) ImageShowScroll *bgImgScroll;
@end

@implementation ZSignViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self.navigationItem setItemWithTitle:@"签到" textColor:kNavigationTitleColor fontSize:18 itemType:center];
    //    [self showNoDataImageView:@"none" withTitle:@"暂无数据哦"];
//    self.dataArray = [NSMutableArray array];
    
    ///右上角按钮
    [self addNavgationRightButtonWithFrame:CGRectMake(0, 0, 40, 40) title:@"签到详情" Image:@"" selectedIMG:@"" tartget:self action:@selector(signAction:)];
    
    if (!self.bgImgScroll) {
//        UIImageView *image = [[UIImageView alloc] init];
//        image.image = WDImgName(@"padd");
        self.bgImgScroll=[[ImageShowScroll alloc]initWithFrame:CGRectMake(0, 1, ScreenWidth, ScreenHeight-64-1) image:WDImgName(@"signback")];
//        self.bgImgScroll.contentSize = CGSizeMake(ScreenWidth, 1000);
//        self.bgImgScroll.backgroundColor = kLightGrayColor;
        self.bgImgScroll.showsVerticalScrollIndicator = false;
        [self.view addSubview:self.bgImgScroll];
    }
    [self loadData];
    
    [AFToast showText:@"签到成功"];
    
    YQCalendarView *view = [[YQCalendarView alloc]initWithFrame:CGRectMake(20,
                                                                           220,
                                                                           ScreenWidth-40,
                                                                           300)];
    [self.bgImgScroll addSubview:view];
    
    //设置选中的日期，格式 yyyy-MM-dd (数组)
    view.selectedArray = @[@"2019-05-02",
                           @"2019-05-03",
                           @"2019-05-09",
                           @"2019-05-10",
                           @"2019-05-12",
                           @"2019-05-13",
                           @"2019-05-15",
                           @"2019-05-16",
                           @"2019-05-17",
                           @"2019-05-18",
                           @"2019-05-19",
                           @"2019-05-20",
                           @"2019-05-22",
                           @"2019-05-23",
                           @"2019-05-24",
                          
                           ];
    
    //单独添加选中个某一天
    [view AddToChooseOneDay:@"2019-05-12"];
    
//--------------------------------------------------自定义显示
    
    view.layer.cornerRadius = 10.f;
    view.layer.masksToBounds = YES;
    //整体背景色
    view.backgroundColor =kBackgroundColor;
    //选中的日期的背景颜色
    //    view.selectedBackColor = [UIColor lightGrayColor];
    //选中的日期下方的图标
    //    view.selectedIcon      = [UIImage imageNamed:@""];
    //下一页按钮的图标
    //    view.nextBTNIcon       = [UIImage imageNamed:@""];
    //    //前一页按钮的图标
    //    view.preBTNIcon        = [UIImage imageNamed:@""];
    //上方日期标题的字体
    //    view.titleFont         = [UIFont systemFontOfSize:17];
    //    //上方日期标题的颜色
    //    view.titleColor        = [UIColor blackColor];
    //    //下方日历的每一天的字体
    //    view.dayFont           = [UIFont systemFontOfSize:17];
    //    //下方日历的每一天的字体颜色
    //    view.dayColor          = [UIColor redColor];
    
    
    //--------------------------------------------------如果需要接收点击后的代理
    view.delegate = self;
    // Do any additional setup after loading the view from its nib.
    ///
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(35, 535, ScreenWidth-70, 45);
    btn.backgroundColor = kSystemtBlue;
    [btn setTitle:@"当月累计签到8天" forState:UIControlStateNormal];
    [btn setTitleColor:kWhiteColor forState:UIControlStateNormal];
    btn.layer.cornerRadius = 15.f;
    btn.layer.masksToBounds = YES;
    [self.bgImgScroll addSubview:btn];
    
    UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(25, 600, ScreenWidth-50, 300)];
    img.image = WDImgName(@"signguide");
    img.layer.cornerRadius = 15.f;
    img.layer.masksToBounds = YES;
    [self.bgImgScroll addSubview:img];
}


//接收点击的代理方法
//使用String格式，是为了避免因时区可能会导致的不必要的麻烦
-(void)YQCalendarViewTouchedOneDay:(NSString *)dateString{
    YYLog(@"点击了：%@",dateString);
}


- (void)loadData{
    ///kDaySignUrl 这个接口返回
    /*
     errorMsg = "",
     result =     {
     createTime = "2019-05-12 10:00:20",
     signNumber = 51,
     signNumberMonth = 8,
     isSign = "",
     },
     errorCode = 0,
     */
    //kMonthSignUrl
    NSDictionary *dic = @{@"userInfo.id":[UserInfoSave shareInstance].uid?:@""};
    [ZNetworkService getRequestWithBaseUrl:kDaySignUrl setParameters:dic success:^(id result) {
        YYLog(@"%@",result);
    } fail:^(NSError *error) {
        
    } delegater:nil];
    
}


-(void)signAction:(UIButton *)btn
{
    ZSignDetailViewController *det = [ZSignDetailViewController new];
    
    [self.navigationController pushViewController:det animated:YES];
}

@end
